package mapeditor.itemselectpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

import mapeditor.mappanel.old.ImageLabelMapView;
import mapeditor.mappanel.old.ListViewScrollBar;

public class ItemSelectionPanel extends JPanel
{
	private ImageLabelSideBar	selected;
	private ImageLabelSideBar	hover;
	private ListViewScrollBar	listScrollBar;

	public ItemSelectionPanel( int items , ListViewScrollBar listScrollBar ) {
		this.listScrollBar = listScrollBar;
		for ( int i = 0 ; i < items ; i++ ) {
			ImageLabelSideBar ci = new ImageLabelSideBar( "Fireaxe " + i ,
					ImageLabelMapView.test , this );
			ci.addMouseListener( ci );
			add( ci );
		}

		setPreferredSize( new Dimension( 200 , 55 * items ) );
	}

	public void paint( Graphics g )
	{
		super.paint( g );
		Color prev = g.getColor( );
		g.setColor( Color.GRAY );
		if ( hover != null ) {
			g.drawRect( hover.getX( ) - 3 , hover.getY( ) - 3 , hover
					.getWidth( ) + 3 , hover.getHeight( ) + 5 );

		}
		g.setColor( Color.BLACK );
		if ( selected != null ) {
			g.drawRect( selected.getX( ) - 3 , selected.getY( ) - 3 , selected
					.getWidth( ) + 3 , selected.getHeight( ) + 5 );
		}
		g.setColor( prev );
	}

	public void labelClicked( ImageLabelSideBar bar )
	{
		selected = bar;
		listScrollBar.setRatio( selected.getY( ) / (double) this.getHeight( ) );
		repaint( );
	}

	public void labelHovered( ImageLabelSideBar bar )
	{
		hover = bar;
		repaint( );
	}

}
